import { AssignStatusType } from '@/ts/base/enum';

export type taskStatus = AssignStatusType;

const antdColorMap: Dictionary<string> = {
  processing: '#4984e4',
  success: '#389e0d',
  error: '#f76c6f',
  info: '',
  warning: '#d46b08',
  assigned: '#616b18',
};

export interface taskStatusInfo {
  status: taskAllStatus;
  label: string;
  color: string;
}

export type taskAllStatus = taskStatus | 'total';

export const statusList: taskStatusInfo[] = [
  { status: AssignStatusType.EMPTY, label: '未接收', color: '' },
  { status: AssignStatusType.RECEIVED, label: '已接收', color: 'processing' },
  { status: AssignStatusType.SUBMITTED, label: '已上报', color: 'warning' },
  { status: AssignStatusType.FINISHED, label: '已完结', color: 'success' },
  { status: AssignStatusType.REJECTED, label: '已退回', color: 'error' },
  { status: AssignStatusType.CHANGED, label: '已变更', color: 'warning' },
  { status: AssignStatusType.ASSIGNED, label: '已分发', color: 'processing' },
];

export const statusMap: Record<taskStatus, taskStatusInfo> = statusList.reduce((a, v) => {
  a[v.status] = v;
  return a;
}, {} as Record<taskAllStatus, taskStatusInfo>);

export function getColorName(color: string | undefined) {
  return antdColorMap[color || ''] || color;
}

export type TaskTreeSummary = {
  [P in taskAllStatus]: number;
};

export function getEmptySummary(): TaskTreeSummary {
  return {
    [AssignStatusType.EMPTY]: 0,
    [AssignStatusType.RECEIVED]: 0,
    [AssignStatusType.SUBMITTED]: 0,
    [AssignStatusType.FINISHED]: 0,
    [AssignStatusType.REJECTED]: 0,
    [AssignStatusType.CHANGED]: 0,
    [AssignStatusType.ASSIGNED]: 0,
    total: 0,
  };
}
